﻿@{
    ViewBag.Title = "图片上传";
    Layout = null;
}

<div id="image_upload_container" class="container">
    <ul>
        <li style="padding: 25px">
            <input type="file" id="iamge_upload_upfile" name="bagFile" style="width:  180px;" />
        </li>
        <li style="padding: 25px">
            <a href="javascript:;" id="iamge_upload_submit"></a>
        </li>
    </ul>
</div>
<script src="~/Content/Scripts/ajaxfileupload.js"></script>
<script type="text/javascript">
    Oneworks.CreatePage('ImageUpload', {
        settings: {
            upload: '/File/Upload',
            uploadswc: '/Content/Plug/jquery-uploadify/uploadify.swf'
        },
        controls: {
            container: $('#image_upload_container'),
            file: $('#iamge_upload_upfile'),
            submit: $('#iamge_upload_submit')
        },
        events: {
            onSuccess: function () { },
            onFailure: function () { },
            onUpload: function () {
                var that = Oneworks.page['ImageUpload'],
                    controls = that.controls,
                    events = that.events,
                    settings = that.settings;
                controls.container.Easyui().mark();
                $.ajaxFileUpload({
                    url: settings.upload,
                    fileElementId: controls.file.attr('id'),
                    dataType: 'json',
                    success: function (data) {
                        controls.container.Easyui().mark(true);
                        data = $.parseJSON(data.responseText);
                        if (data) {
                            if (data.status == 1)
                                events.onSuccess(data);
                            else {
                                events.onFailure(data);
                            }
                        } else {
                            Oneworks.Easyui.alert('上传文件出现异常');
                        }
                    }
                });
            }
        }
    }, function () {
        var that = this;
        var controls = that.controls,
            events = that.events,
            settings = that.settings;
        controls.init = function () {
            controls.submit.linkbutton({ text: '上传' });
        };
        events.init = function () {
            controls.submit.click(events.onUpload);
            var p = controls.container.parent(),
                h = p.height(),
                w = p.width();
            controls.container.css({
                width: w,
                height: h
            });
        };
        controls.init();
        events.init();
    });

</script>

